package com.zlzxm.sorting.ui.vm

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.chad.library.adapter.base.entity.node.BaseNode
import com.zlzxm.sorting.globe.picOne
import com.zlzxm.sorting.ui.view.sortview.RootNode
import com.zlzxm.sorting.ui.view.sortview.SecondNode
import com.zlzxm.sorting.util.ui.manager.BaseViewModel
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

/**
 *
 *CREATE BY zlzxm ON 2022/8/22
 *
 */
class VmSortViewProduct : BaseViewModel() {

    var id:String? =null

    val listData = MutableLiveData<MutableList<BaseNode>>()


    override fun loadPageData() {

        id?.let {

            viewModelScope.launch {

                delay(1000)

                val list: MutableList<BaseNode> = ArrayList()

                var title = ""
                when (id) {

                    "0" -> {

                        title = "水果"

                    }
                    "1" -> {
                        title = "肉"

                    }
                    "2" -> {
                        title = "水产"

                    }

                    "3" -> {
                        title = "冷冻品"

                    }
                    "4" -> {
                        title = "禽蛋"

                    }
                    "5" -> {
                        title = "豆制品"

                    }
                    "6" -> {
                        title = "面食"

                    }

                    "7" -> {
                        title = "腌制品"

                    }

                    "8" -> {
                        title = "饮料"

                    }


                }
                for (i in 0..7) {

                    //SecondNode 的 list
                    val secondNodeList: MutableList<BaseNode> = ArrayList()
                    for (n in 0..5) {
                        val seNode = SecondNode("第${n}件产品")
                        seNode.face = picOne
                        seNode.total = 10
                        seNode.process = 0
                        secondNodeList.add(seNode)
                    }
                    val entity = RootNode(secondNodeList, " ${title}--${i}大类")
                    list.add(entity)
                }

                listData.value = list
            }
        }


    }


}